<style>
.add_table{
    font-size: 12px;
}

    .add_label {
        margin-left: 10px;
    }

    .uploadpic {
        float: left;
        width: 295px;
        text-align: center;
        height: 165px;
    }

    .uploadpic h3 {
        text-align: left;
        border: 1px solid #95B8E7;
        float: left;
        padding: 4px;
        background-color: #95B8E7;
        color: #FFF;
    }

    .up-content {
        border: 1px solid #95B8E7;
        padding: 4px;
    }

    .w10 {
        float: left;
        width: 10px;
        color: #FFF;
    }

    .items {
        padding: 10px 0 4px 0;
        border-top: solid 1px #D6D4D4;
        display: block;
    }

    #dd div {
        padding-right: 10px;
        padding-bottom: 10px;
    }

    .addItems {
        float: left;
    }

    /*表格样式  */
    .add_table {
        width: 100%;
        border: 1px solid #0e90d2;
    }

    .add_table th {
        width: 80px;
        background-color: #E0ECFF;
        padding: 8px 0 8px 0;
        border-right: solid 1px #95B8E7;
        border-bottom: solid 1px #95B8E7;
    }

    .add_table td {
        border-bottom: solid 1px #95B8E7;
    }

    .add_table tr {
        border: solid 1px #95B8E7;
    }

    .tb_head {
        text-align: center;
        padding: 10px;
        background-color: #E0ECFF;
        font-size: 20px;
        font-weight: bold;
    }

    .inline {
        display: inline;
        padding-right: 5px;
    }

    .row_container {
        padding: 8px 5px 5px 5px;
    }


    .add_degx_title {
        font-size: 20px;
        color: #0e2d5f;
        text-align: center;
        padding: 10px;
        font-weight: bold;
    }

    .fl_edit_tool {
        border: 1px solid red;
    }
</style>
<link href="__PUBLIC__/js/jquery.json-viewer/jquery.jsonview.css" rel="stylesheet">
<script type="text/javascript" src="__PUBLIC__/js/jquery.json-viewer/jquery.jsonview.js"></script>
<div id="ly_degx_add" class="easyui-layout" data-options="fit:true,border:false">
    <div data-options="region:'center',title:''" style="padding:5px;background:#eee;">

        <div class="add_degx_title" id="json1">添加定额工时工序</div>
        <form id="add_degx_form" action="__APP__/Home/Degx/add" enctype="multipart/form-data" method="post"
              style="padding:10px;">
            <table class="add_table">
                <tr>
                    <th>生产信息</th>
                    <td>
                        <div class="row_container" style="background: #FFFEE6;">
                            <div class="inline">
                                <span class="add_label">车间：</span>
                                <input id="cj_add_degx" name="cj" class="easyui-textbox"
                                       data-options="iconCls:'',editable:true,required:false,panelHeight:'auto'"
                                       style="width:100px"/>
                            </div>
                            <div class="inline">
                                <span class="add_label">工位：</span>
                                <input id="gw_add_degx" class="easyui-combogrid"
                                       data-options="editable:false,required:false"
                                       name="gw" style="width:200px;"/>
                            </div>
                            <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'"
                               onclick="pipei()">匹配</a>
                        </div>
                    </td>

                </tr>
                <th>车型分类</th>
                <td style="background-color:rgba(204, 204, 204, 0.4);">
                    <div class="row_container">

                        <div class="panel" style="display: block;">
                            <div class="easyui-panel panel-body panel-body-noheader" style="padding: 5px; width: 100%;"
                                 title="">
                                <span class="add_label">平台：</span>
                                <input class="easyui-combobox" name="pt" id="add_degx_pt"
                                       data-options="editable:false,panelHeight:'auto',required:false,multiple:'true'"
                                       style="width:400px;">


                                <span class="add_label">车型分类：</span>
                                <input class="easyui-combobox" name="cl" id="add_degx_cl"
                                       data-options="editable:false,panelHeight:'auto',required:false,multiple:'true'"
                                       style="width:400px;">


                                <br>
                                <span class="add_label">驱动：</span>
                                <input class="easyui-combobox" name="qd" id="add_degx_qd"
                                       data-options="editable:false,panelHeight:'auto',required:false,multiple:'true'"
                                       style="width:400px;">


                                <span class="add_label">燃料型式：</span>
                                <input class="easyui-combobox" name="rl" id="add_degx_rl"
                                       data-options="editable:false,panelHeight:'auto',required:false,multiple:'true'"
                                       style="width:400px;">


                                <br>
                                <br>
                                <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'"
                                   onclick="save_fl_all()">保存多个选项分类</a>

                                <span class="add_label">其他：</span>
                                <input id="" name="qtfl" class="easyui-textbox"
                                       data-options="iconCls:'',editable:true,required:false" style="width:400px"/>
                                <span class="add_label">是否选装：</span>
                                <input name="xuanzhuang" class="easyui-switchbutton" checked  data-options="onText:'是',offText:'否'">

                            </div>
                        </div>
                    </div>
                </td>
                </tr>

                <tr>
                    <th>工序名称</th>
                    <td>
                        <input name="title" class="easyui-textbox" id="content"  style="width: 100%; "
                               data-options="required:true,prompt:'请输入简短的工序名称'"/>
                        <br/>
                    </td>
                </tr>
                <tr>
                    <th>标签</th>
                    <td>


                        <input name="tags" id="add_gx_tags"  data-options="validType: ['uniquetag']" class="easyui-tagbox" value="" style="width:100%"  data-options="required:true,prompt:''">
                        <br/>
                    </td>
                </tr>
                <tr>
                    <th>工序描述</th>
                    <td>
                    <textarea name="sm" class="easyui-textbox" id="discr" style="width: 100%; height: 46px;"
                              data-options="required:true"></textarea>
                        <br/>
                    </td>
                </tr>
                <tr>
                    <th>上传图片</th>
                    <td>
                        <div class="easyui-panel" style="padding:5px;">
                            <input name="pics[]" id="add_degx_pics" style="width:80%;"
                                   data-options="multiple:true,buttonText:'上传图片',buttonIcon:'icon-standard-bullet-picture',buttonAlign:'right',accept:'image/*'"
                                   class="easyui-filebox">
                        </div>
                    </td>
                </tr>
                <tr>
                    <th>工艺文件</th>
                    <td>
                        <div class="easyui-panel" style="padding:5px;">
                            <input name="fjs[]" id="add_degx_file" style="width:80%;"
                                   data-options="multiple:true,buttonText:'上传工艺文件',buttonIcon:'icon-standard-bullet-picture',buttonAlign:'right',accept:'application/pdf,application/msword'"
                                   class="easyui-filebox">
                        </div>
                    </td>
                </tr>
                <tr>
                    <th>备注</th>
                    <td>

                    <textarea name="bz" class="easyui-textbox" id="beizhu" style="width: 100%; height: 46px;" onkeyup=""
                              data-options=""></textarea>
                        <br/>
                    </td>
                </tr>
            </table>
        </form>
    </div>

    <div data-options="region:'east',iconCls:'icon-reload',title:'East',split:true,collapsed:true"
         style="width:500px;"></div>
</div>


<div style="background-color: #E0ECFF;
    bottom: 0px;
    position: absolute;
    width: 100%;
    border: 1px solid #95b8e7;">
    <a href="#" class="easyui-linkbutton" onclick='newDegx()'
       data-options="iconCls:'icon-standard-page-word',plain:true">新建定额工序</a>
    <a href="#" class="easyui-linkbutton" onclick='clearDegxForm()'
       data-options="iconCls:'icon-standard-coins-delete',plain:true">清空</a>
    <a href="#" class="easyui-linkbutton" onclick='back_degx_add()'
       data-options="iconCls:'icon-standard-cup-go',plain:true">返回</a>
</div>
<include file="windows"/>
<script>

    $('#add_gx_tags').tagbox({
        buttonText: '清空',
        onClickButton:function(){
            $(this).tagbox('clear');
        }
    });

    // 对tagbox去重
    // $.extend($.fn.validatebox.defaults.rules, {
    //     uniquetag: {
    //         validator: function(value, param){
    //             var tb = $(this).closest('.tagbox').prev();
    //             var values = tb.tagbox('getValues');
    //             var arr=value.split(",")
    //             var n=arr.length-1
    //             var item=arr[n]
    //             console.log($.inArray(item, values))
    //             return $.inArray(value, values)==-1;
    //
    //         },
    //         message: '标签已经存在.'
    //     }
    // })

    $("#add_degx_pt").combobox({
        url: '__APP__/Home/Degx/cxfl',
        valueField: 'value',
        textField: 'title',
        groupField: 'groups',
        queryParams: {
            "fl": 'pt'
        },
        icons: [{
            iconCls: 'icon-standard-accept',
            handler: function (e) {
                var data = $(e.data.target).combobox("getData");
                var arr = new Array()
                for (var i = 0; i < data.length; i++) {
                    arr.push(data[i].value)
                }
                $(e.data.target).combobox('setValues', arr);
            }
        }, {
            iconCls: 'icon-standard-cancel',
            handler: function (e) {
                $(e.data.target).combobox('clear');
            }
        }, {
            iconCls: 'icon-standard-database-save',
            handler: function (e) {
                save_fl('平台', e)
            }
        }, {
            iconCls: 'icon-standard-newspaper-go',
            handler: function (e) {
                load_fl('平台', e)
            }
        }]
    });

    /**
     * 显示添加分类界面
     * @param fl
     * @param item
     */
    function save_fl(fl, e) {
        // 打开保存窗口
        $("#save_fl").dialog("open").dialog('setTitle', '&nbsp;&nbsp;添加分类项');
        var arr = {
            'type': '',
            'value': {}
        }
        var val = $(e.data.target).combobox("getValues");

        var item = {
            'lb': fl,
            'value': val
        }
        arr['value'][0] = item
        arr['type'] = 'sigle'
        var shuju = JSON.stringify(arr)
        var data = new Array()
        data['shuju'] = shuju
        data['lb'] = fl

        // 将数据存入隐藏的input中
        $('#save_fl_form').form("load", data)
        $("#json").JSONView(arr);
    }

    function save_fl_all() {
        // 打开保存窗口
        $("#save_fl").dialog("open").dialog('setTitle', '&nbsp;&nbsp;添加分类项');
        var arr = {
            'type': '',
            'value': {}
        }
        var en = ['pt', 'cl', 'qd', 'rl'];
        var chs = ['平台', '车型', '驱动', '燃料'];

        for (var i = 0; i < en.length; i++) {
            var str = 'add_degx_' + en[i]

            var val = $("#" + str).combobox("getValues");
            var fl = chs[i];
            var item = {
                'lb': fl,
                'value': val
            }
            arr['value'][i] = item
        }
        arr['type'] = 'multiple'
        var shuju = JSON.stringify(arr)
        var data = new Array()
        data['shuju'] = shuju
        data['lb'] = '混合'

        // 将数据存入隐藏的input中
        $('#save_fl_form').form("load", data)
        $("#json").JSONView(arr);
    }

    $("#add_degx_cl").combobox({
        url: '__APP__/Home/Degx/cxfl',
        valueField: 'value',
        textField: 'title',
        groupField: 'groups',
        queryParams: {
            "fl": 'cl'
        },
        icons: [{
            iconCls: 'icon-standard-accept',
            handler: function (e) {
                var data = $(e.data.target).combobox("getData");
                var arr = new Array()
                for (var i = 0; i < data.length; i++) {
                    arr.push(data[i].value)
                }
                $(e.data.target).combobox('setValues', arr);
            }
        }, {
            iconCls: 'icon-standard-cancel',
            handler: function (e) {
                $(e.data.target).combobox('clear');
            }
        }, {
            iconCls: 'icon-standard-database-save',
            handler: function (e) {
                save_fl('车型', e)
            }
        }, {
            iconCls: 'icon-standard-newspaper-go',
            handler: function (e) {
                load_fl('车型', e)
            }
        }]
    });
    $("#add_degx_qd").combobox({
        url: '__APP__/Home/Degx/cxfl',
        valueField: 'value',
        textField: 'title',
        groupField: 'groups',
        queryParams: {
            "fl": 'qd'
        },
        icons: [{
            iconCls: 'icon-standard-accept',
            handler: function (e) {
                var data = $(e.data.target).combobox("getData");
                var arr = new Array()
                for (var i = 0; i < data.length; i++) {
                    arr.push(data[i].value)
                }
                $(e.data.target).combobox('setValues', arr);
            }
        }, {
            iconCls: 'icon-standard-cancel',
            handler: function (e) {
                $(e.data.target).combobox('clear');
            }
        }, {
            iconCls: 'icon-standard-database-save',
            handler: function (e) {
                save_fl('驱动', e)
            }
        }, {
            iconCls: 'icon-standard-newspaper-go',
            handler: function (e) {
                load_fl('驱动', e)
            }
        }]
    });
    $("#add_degx_rl").combobox({
        url: '__APP__/Home/Degx/cxfl',
        valueField: 'value',
        textField: 'title',
        groupField: 'groups',
        queryParams: {
            "fl": 'rl'
        },
        icons: [{
            iconCls: 'icon-standard-accept',
            handler: function (e) {
                var data = $(e.data.target).combobox("getData");
                var arr = new Array()
                for (var i = 0; i < data.length; i++) {
                    arr.push(data[i].value)
                }
                $(e.data.target).combobox('setValues', arr);
            }
        }, {
            iconCls: 'icon-standard-cancel',
            handler: function (e) {
                $(e.data.target).combobox('clear');
            }
        }, {
            iconCls: 'icon-standard-database-save',
            handler: function (e) {
                save_fl('燃料', e)
            }
        }, {
            iconCls: 'icon-standard-newspaper-go',
            handler: function (e) {
                load_fl('燃料', e)
            }
        }]
    });

    $('#lb').combobox({
        onSelect: function (param) {
            console.log(param)

            var n = param.value - 1;
            var str = ['工作自检、互检与专检相结合以确保正确无误,自检七步法，互检三步法，专检五步法。', '对缺少标识，未经检验及不合格的零部件不得装配使用，装配前应主动检查零部件的正确性和外观质量，发现不合格产品及零部件不应装配，应及时向质量人员报告。', '1.装配工在装配之前，应首先熟悉本工位的工艺文件、图纸及技术要求；并在装配工作中，严格执行工艺及产品图纸等技术要求。2.装配完毕后，装配工应自检所装配的内容是否符合工艺要求，保证质量，最后应及时在整车装配检验跟单上签名。3.装配中所使用的各种工具、夹具、量具应符合工艺要求、且具备合格标准及完整性。4.各零部件及分总成，在装配中应保持清洁干净，不应直接接触地面，装配场地应清洁整齐，做到文明生产。5.装配工作中作业人员不得擅自更改装配挂单等工艺文件，防止错装、漏装；工作自检、互检与专检相结合以确保正确无误。', '设计文件未及时转化'];
            $('#gy').textbox('setText', str[n]);
            console.log(str[n])

            // str[param.value]
        }
    });


    function back_degx_add() {
        var tab = $('#tab').tabs('getSelected');
        tab.panel('refresh', APP + '/Home/Degx/index');
    }

    function newDegx() {
        $('#add_degx_form').form('submit', {

            url: APP + '/Home/Degx/add',
            onSubmit: function (param) {
                // param.gy = $('#gy').textbox('getText');
            },

            success: function (data) {
                $('#add_degx_form').form('clear');
                $.messager.confirm('确认', data + '是否要返回列表页面', function (r) {
                    if (r) {
                        var tab = $('#tab').tabs('getSelected');
                        tab.panel('refresh', APP + '/Home/Degx/index');
                    }
                });
            }
        });
    }

    function clearDegxForm() {
        $.messager.confirm('确认', '您确认想要清空记录吗？', function (r) {
            if (r) {
                $('#add_degx_form').form('clear');
            }
        });
    }

    $('#cj_add_degx').combobox({
        valueField: 'id',
        url: APP + '/Admin/Trem/cjList',
        textField: 'title',
        editable: false,
        onSelect: function (rec) {
            $('#gw_add_degx').combogrid({
                panelWidth: 200,
                idField: 'title',
                textField: 'title',
                multiple: true,
                striped: true,
                url: APP + '/Admin/Trem/cjList?pid=' + rec.id,
                columns: [[
                    {field: 'title', title: '名称', width: 120}
                ]]
            });
            $('#gw_add_degx').combobox('clear');
        }
    });


    // 匹配MES信息
    function pipei() {

        // 匹配之前西安清空
        $('#lshqj').textbox('clear');
        $('#jsh').textbox('clear');
        $('#cx').textbox('clear');

        // $('#fkbm').textbox('clear');
        var lsh = $('#lshpp').textbox('getText');
        if (lsh != "") {
            $.post("__APP__/Home/Zhiliang/pipei", {lsh: lsh}, function (result) {
                // $("span").html(result);
                console.log(result);
                if (result.status == '1') {
                    $('#lshqj').textbox('setValue', result.data.lshqj);
                    $('#jsh').textbox('setValue', result.data.sjjhh);
                    $('#cx').textbox('setValue', result.data.cl);

                } else {
                    $.messager.alert('匹配车型信息', result.data, 'info');
                }

            }, "json");
        } else {
            $.messager.alert('匹配车型信息', '请输入流水号', 'info');
        }
    }

    /**
     * 平台，选择所有
     * add_degx_pt
     */

    function selectAll_add_gx(item) {
        var data = $("#" + item).combobox("getData");
        var arr = new Array()
        for (var i = 0; i < data.length; i++) {
            arr.push(data[i].value)
        }
        $data = $("#" + item).combobox("select", arr);
    }


    function clearAll_add_gx(item) {
        $("#" + item).combobox("clear");
    }


    /**
     * 保存分类项目
     */
    function save_fls() {
        $('#save_fl_form').form('submit', {
            url: APP + '/Home/Degx/savefl',
            onSubmit: function (param) {
            },
            success: function (data) {
                data = $.parseJSON(data);
                $('#save_fl_form').form('clear');
                $.messager.alert('成功', data.msg, 'info');

                $('#load_fl_dg').datagrid("load", {
                    lb: '',

                })
            }
        });
    }

    /**
     * 载入分类界面
     * @param fl
     * @param item
     */
    function load_fl(fl, item) {
        $("#load_fl").dialog("open").dialog('setTitle', '&nbsp;&nbsp;载入分类项');
        var dataArr = new Array();
        dataArr.lb = fl
        dataArr.lbs = fl
        dataArr.item = item
        $('#load_fl_form').form('load', dataArr)

        // $('#load_fl_leibie').combobox('setValue', fl);


    }

    function clearForm_save_fl() {
        $('#save_fl_form').form('clear')
    }
</script>
